<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<html>
	<head>
		<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
		<meta name="viewport" content="width=device-width,initial-scale=1">
		<title>我的伙伴</title>
		<link rel="stylesheet" th:href="@{/css/jquery.mobile-1.4.5.min.css }"/>
		<script th:src="@{/js/jquery.min.js}"></script>
		<script th:src="@{/js/jquery.mobile-1.4.5.min.js}"></script>
		<link rel="stylesheet" th:href="@{/css/iconfont.css}"/>
		<script>
			$("document").ready(function(){
				var user=JSON.parse(window.sessionStorage.getItem("user"));
				var userid=user.userid;
				var name=user.name;
				var email=user.email;
				var tel=user.tel;
				$("#userid").val(userid);
				$("#name").val(name);
				$("#email").val(email);
				$("#tel").val(tel);
			});
			function updateUser(){
				var user=JSON.parse(window.sessionStorage.getItem("user"));
				var userid=user.userid;
				var name=$("#name").val();
				var email=$("#email").val();
				var tel=$("#tel").val();
				if(name==""){
					$("#NameisNull").popup('open');
				}else{
					$.post("/UserController/updateUser",$("#editForm").serialize(), function (data) {
						if(data=="success"){
							console.log("success");
							var newObj={"userid":userid,"email":email,"tel":tel,"name":name}
							window.sessionStorage.setItem("user",JSON.stringify(newObj));
							window.location = "/ViewController/goUserPanel2";
						}else{
							console.log("失败");
							alert("更改失败");
							}
					});
				}
			}
			function close1(){
				$("#NameisNull").popup('close');
			}
		</script>
	</head>
	<body>
		<div data-role = "page">
			<div data-role = "header">
				<a href="/ViewController/goUserPanel2" data-ajax = "false" data-icon = "back">返回</a>
				<h1>修改用户信息</h1>
			</div>
			<div data-role = "content">
				<form id="editForm">
					<input type="hidden" name="userid" id="userid" />
				<div>
				<label>昵称：</label>
				<input type="text" name="name" id="name"/>
				</div>
				
				<div>
				<label>邮箱：</label>
				<input type="text" name="email" id="email"/>
				</div>
				
				<div>
				<label>电话：</label>
				<input type="text" name="tel" id="tel"/>
				</div>
				</form>
				<a onclick="updateUser()" data-ajax = "false" data-role = "button">保存</a>
				<div data-role = "popup" id="NameisNull" class="ui-content">
					<a href="#" data-role = "button" data-icon = "delete" data-iconpos = "notext" class="ui-btn-right" onclick="close1()">Close</a>
					<div>昵称不能为空</div>
				</div>
			</div>
		</div>
	</body>
</html>
